package com.ruoyi.system.template.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.template.domain.Pb1ContractTemplate;
import com.ruoyi.system.template.service.IPb1ContractTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同模板Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/template/template")
public class Pb1ContractTemplateController extends BaseController
{
    @Autowired
    private IPb1ContractTemplateService pb1ContractTemplateService;

    /**
     * 查询合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('template:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pb1ContractTemplate pb1ContractTemplate)
    {
        startPage();
        List<Pb1ContractTemplate> list = pb1ContractTemplateService.selectPb1ContractTemplateList(pb1ContractTemplate);
        return getDataTable(list);
    }

    /**
     * 导出合同模板列表
     */
    @PreAuthorize("@ss.hasPermi('template:template:export')")
    @Log(title = "合同模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Pb1ContractTemplate pb1ContractTemplate)
    {
        List<Pb1ContractTemplate> list = pb1ContractTemplateService.selectPb1ContractTemplateList(pb1ContractTemplate);
        ExcelUtil<Pb1ContractTemplate> util = new ExcelUtil<Pb1ContractTemplate>(Pb1ContractTemplate.class);
        util.exportExcel(response, list, "合同模板数据");
    }

    /**
     * 获取合同模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('template:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(pb1ContractTemplateService.selectPb1ContractTemplateByTemplateId(templateId));
    }

    /**
     * 新增合同模板
     */
    @PreAuthorize("@ss.hasPermi('template:template:add')")
    @Log(title = "合同模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pb1ContractTemplate pb1ContractTemplate)
    {
        return toAjax(pb1ContractTemplateService.insertPb1ContractTemplate(pb1ContractTemplate));
    }

    /**
     * 修改合同模板
     */
    @PreAuthorize("@ss.hasPermi('template:template:edit')")
    @Log(title = "合同模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pb1ContractTemplate pb1ContractTemplate)
    {
        return toAjax(pb1ContractTemplateService.updatePb1ContractTemplate(pb1ContractTemplate));
    }

    /**
     * 删除合同模板
     */
    @PreAuthorize("@ss.hasPermi('template:template:remove')")
    @Log(title = "合同模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(pb1ContractTemplateService.deletePb1ContractTemplateByTemplateIds(templateIds));
    }
}
